package com.wanglianyun.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

//异步调用
@Configuration
@EnableAsync
public class ThreadPoolConfig {

    @Bean(name = "registerSuccessExecutor")
    public ThreadPoolExecutor getLabelThreadPool() {
        return new ThreadPoolExecutor(20, 100, 5,
                TimeUnit.SECONDS, new LinkedBlockingDeque<>(40),
                //传入自定义的线程工厂
                new CustomNameThreadFactory("registerSuccessEvent"),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}